import { provide } from "vue";
import { useStore } from "vuex";

export default function () {
  let store = useStore();
  let menuInfo = (data) => {
    // console.log(data, ">>><<<<");

    let sideBarHead = recursion(data).reverse();

    store.commit("setState", { key: "breadcrumb", data: sideBarHead });
    // return data
  };
  provide("menuInfo", menuInfo); //通过provide 注入menuInfo

  // 面包屑 数据重组
  function recursion(data, info = []) {
    info.push({
      name: data.name,
      url: data.url,
    });
    if (data.parent) {
      recursion(data.parent, info);
    }
    return info;
  }

  return false;
}
